package com.hnl;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.aware.HNLTalentAware;
import com.hnl.dao.ActivityDAO;
import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.to.Activity;
import com.hnl.to.wrapper.ActivityWrapper;
import com.hnl.util.JSONResponseUtil;

@SuppressWarnings("serial")
public class LoadpersonalActList extends HttpServlet implements HNLTalentAware {
	public static final Logger LOG = LoggerFactory
			.getLogger(LoadpersonalActList.class);

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter writer = resp.getWriter();
		try {
			String talentID = req.getParameter(ATTRIBUTE_TALENT_ID);

			ActivityDAO activityDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getActivityDAO();
			Collection<Activity> activityColletion = activityDAO
					.loadOneTalentActivity(Integer.valueOf(talentID));

			Collection<ActivityWrapper> activityWrapperCollection = new Vector<ActivityWrapper>();

			for (Activity activity : activityColletion) {
				ActivityWrapper newActivityWrapper = new ActivityWrapper(
						activity);
				newActivityWrapper.getActivity_typeText();
				newActivityWrapper.getModifiedUserIDText();
				activityWrapperCollection.add(newActivityWrapper);
			}
			
			writer.println(JSONResponseUtil
					.getJSONObjectString(activityWrapperCollection));

		} catch (DAOException e) {
			LOG.error("error laoding Talent", e);
		} finally{
			writer.close();
		}
	}
}
